package September20;

import java.util.Scanner;

public class StringCount {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入第一个字符串:");
        String sub = scanner.nextLine();
        System.out.println("请输入第二个字符串:");
        String str = scanner.nextLine();

        int count = 0;
        int fromIndex = 0;

        // 循环直到找不到子字符串
        while ((fromIndex = str.indexOf(sub, fromIndex)) != -1) {
            count++;
            fromIndex += sub.length(); // 移动到找到的子字符串之后，继续查找
        }

        System.out.println("第一个字符串在第二个字符串中出现了 " + count + " 次。");
        scanner.close();
    }
}
